package cn.xiaolang.function.file_manage;

import java.io.IOException;
import java.nio.file.*;

/**
 * 文件遍历
 *
 * @author fuhw/DeanKano
 * @date 2018-10-16
 */
public class FilesWalk {

    /**
     * 遍历文件夹
     */
    public static void main(String[] args) throws IOException {
        Path path = Paths.get("F:/test-upload/temp");
        Files.walk(path, 1)
                .map(path::resolveSibling).forEach(System.err::println);
        Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir,
                                                                   java.nio.file.attribute.BasicFileAttributes attrs) throws IOException {
                System.err.println("正在访问目录：" + dir);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, java.nio.file.attribute.BasicFileAttributes attrs)
                    throws IOException {
                System.err.println("正在访问文件：" + file);
                return FileVisitResult.CONTINUE;
            }
        });
    }
}
